package splash;

import seniorproject.gamecoganh.MainMenu;
import seniorproject.gamecoganh.R;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class SplashView extends SurfaceView implements SurfaceHolder.Callback {
	private SplashThread splashThread;
	private Resources resources;
	private Bitmap bitmap;
	private Paint paint;
	private Intent intent;

	public SplashView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		getHolder().addCallback(this);
		splashThread = new SplashThread(getHolder(), this);
		resources = this.getResources();
		bitmap = BitmapFactory.decodeResource(resources, R.drawable.splashv1);
		paint = new Paint();
		setFocusable(true);
		getContext();
		intent = new Intent();
		intent.setClass(context, MainMenu.class);
	}

	public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub

	}

	public void surfaceCreated(SurfaceHolder arg0) {
		// TODO Auto-generated method stub
		splashThread.setFinish(false);
		splashThread.start();
	}

	public void surfaceDestroyed(SurfaceHolder arg0) {
		// TODO Auto-generated method stub
		getContext().startActivity(intent);
		splashThread.setFinish(true);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		canvas.drawColor(Color.BLACK);
		canvas.drawBitmap(bitmap, 0, 0, paint);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		if (event.getAction() == MotionEvent.ACTION_DOWN)
			synchronized (this) {
				this.surfaceDestroyed(getHolder());
			}
		return true;
	}
}
